package cc.magicjson.example.demo.web.service;

import cc.magicjson.example.demo.domain.UserInfo;
import cc.magicjson.example.demo.threadlocal.context.UserContext;
import cc.magicjson.example.demo.web.respository.UserRepository;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

/**
 * {@link}
 *
 * @author <a href="mailto:it_magicjson@163.com">MagicJson</a>
 * @since 1.0.0
 */
@Service
public class UserServiceImpl implements UserService {
	private final UserRepository userRepository;

	public UserServiceImpl(UserRepository repository){
		this.userRepository = repository;
	}


	@Override
	public UserInfo getUserInfo(String token) {
		return userRepository.getUserInfo(token);
	}


	@Async("taskExecutor")
	public void ayncGetUserInfo() {
		System.out.printf("current thread:[%s], asyncUserInfo:%s"
				,Thread.currentThread().getName()
				, UserContext.getUserInfo());
	}

}
